package lovo01.modifyhomework;

/**
 * 超级数组
 */
public class SuperArray {
    private Object[] objs = new Object[0];

    /**
     * 将添加的元素放到最后一位
     */
    public void add(Object value){
        Object[] ary = new Object[objs.length + 1];
        for (int i = 0;i < objs.length;i++){
            ary[i] = objs[i];
        }
        ary[ary.length - 1] = value;
        objs = ary;
    }

    /**
     * 删除指定下标的元素
     * @param index
     */
    public void remove(int index){
        Object[] ary = new Object[0];
        for (int i = 0;i < ary.length;i++){
            if (i >= index){
                ary[i] = objs[i + 1];
            }
            ary[i] = objs[i];
        }
        objs = ary;
    }

    /**
     * 访问超级数组的长度
     * @return
     */
    public int size(){
        return objs.length;
    }

    /**
     * 获取数组下标的元素
     * @param index
     * @return
     */
    public Object get(int index){
        return objs[index];
    }

    public void setObjs(Object[] objs){
        this.objs = objs;
    }
}
